'use strict';

let Fiber = require('fibers');

let um = require('..');
let Types = require('..').Types;

um.enablePersist();
let session = um.createSession({
    backend: 'mongodb',
    uri: 'mongodb://localhost/authendata',
    options: {
        user: 'kinuxroot',
        pass: '123456'
    }
});

let Tag = um.model.createModel('Tag', {
    name: Types.Text()
});
let TagDao = session.getDao(Tag);

function main() {
    let tags = [];
    for ( let i = 0; i < 5000; i ++ ) {
        tags.push({
            name: `tag${i}`
        });
    }
    
    console.log('Begin Insert');
    let startTime = Date.now();
    TagDao.insertMany(tags);
    let endTime = Date.now();
    console.log(`Use time: ${endTime - startTime}`);
    console.log('Insert tags successfully');

    process.exit(0);
}

Fiber(main).run();
